const fs = require('fs');
const path = require('path');

// 验证医生功能目录页面和相关文件
function verifyDoctorPages() {
    console.log('=== 医生端功能目录验证 ===\n');
    
    // 1. 检查医生功能目录页面是否存在
    const doctorDirPath = path.join(__dirname, 'entry', 'src', 'main', 'ets', 'features', 'doctor', 'DoctorFunctionDirectory.ets');
    const doctorDirExists = fs.existsSync(doctorDirPath);
    console.log(`医生功能目录页面存在: ${doctorDirExists ? '✓' : '✗'}`);
    
    // 2. 检查main_pages.json配置
    const pagesJsonPath = path.join(__dirname, 'entry', 'src', 'main', 'resources', 'base', 'profile', 'main_pages.json');
    let pagesJsonExists = fs.existsSync(pagesJsonPath);
    let hasDoctorDirInConfig = false;
    
    if (pagesJsonExists) {
        const pagesJsonContent = fs.readFileSync(pagesJsonPath, 'utf8');
        hasDoctorDirInConfig = pagesJsonContent.includes('"features/doctor/DoctorFunctionDirectory"');
        console.log(`医生功能目录在页面配置中: ${hasDoctorDirInConfig ? '✓' : '✗'}`);
    } else {
        console.log('页面配置文件不存在: ✗');
    }
    
    // 3. 检查Login页面的跳转配置
    const loginPath = path.join(__dirname, 'entry', 'src', 'main', 'ets', 'pages', 'Login.ets');
    let loginExists = fs.existsSync(loginPath);
    let loginRedirectCorrect = false;
    
    if (loginExists) {
        const loginContent = fs.readFileSync(loginPath, 'utf8');
        loginRedirectCorrect = loginContent.includes('targetPage = \'features/doctor/DoctorFunctionDirectory\'');
        console.log(`登录页面医生角色跳转配置正确: ${loginRedirectCorrect ? '✓' : '✗'}`);
    } else {
        console.log('登录页面不存在: ✗');
    }
    
    // 4. 检查医生功能相关页面
    const doctorPages = [
        'PatientList',
        'HealthRecords', 
        'RiskAlerts',
        'Prescriptions',
        'Appointments',
        'Statistics',
        'Settings'
    ];
    
    console.log('\n医生功能页面存在性检查:');
    let allDoctorPagesExist = true;
    
    doctorPages.forEach(pageName => {
        const pagePath = path.join(__dirname, 'entry', 'src', 'main', 'ets', 'features', 'doctor', `${pageName}.ets`);
        const exists = fs.existsSync(pagePath);
        console.log(`  ${pageName}: ${exists ? '✓' : '✗'}`);
        if (!exists) allDoctorPagesExist = false;
    });
    
    console.log('\n=== 验证总结 ===');
    const allConfigCorrect = doctorDirExists && pagesJsonExists && hasDoctorDirInConfig && loginExists && loginRedirectCorrect && allDoctorPagesExist;
    
    if (allConfigCorrect) {
        console.log('✓ 所有医生端功能目录配置正确!');
        console.log('\n医生登录后将跳转到功能目录，可访问以下功能:');
        console.log('  - 患者总览');
        console.log('  - 患者管理');
        console.log('  - 健康记录');
        console.log('  - 风险预警');
        console.log('  - 处方管理');
        console.log('  - 预约管理');
        console.log('  - 统计分析');
        console.log('  - 医生设置');
    } else {
        console.log('✗ 存在配置问题，请检查上述验证项。');
    }
}

// 运行验证
verifyDoctorPages();